package com.nurt.dto;

import com.alibaba.fastjson2.JSON;
import com.nurt.utils.ReturnCode;

public class ResultDto<T> {
    private int status;
    private String message;
    private T data;
    private String error;

    public ResultDto() {
    }

    public ResultDto(int status, String message, T data, String error) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.error = error;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public static <T> String success(T data) {
        ResultDto<T> result = new ResultDto<>(ReturnCode.SUCCESS.getCode(), "Operation successful.", data, null);
        return JSON.toJSONString(result);
    }

    public static <T> String fail(int code, String message) {
        ResultDto<T> result = new ResultDto<>(code, message, null, null);
        return JSON.toJSONString(result);
    }
}